package com.tul.exercise.base.java8.lambda;


/**
 * 定义除法函数接口
 */
@FunctionalInterface
public interface DoubleDiv {
    double apply(double a, double b);

    /**
     * double 除法
     * @param a 除数
     * @param b 被除数
     * @return 商
     * @throws ArithmeticException
     */
    default double div(double a, double b) throws ArithmeticException {
        double result;
        try {
            result = a / b;
        } catch (Exception e) {
            //throw ArithmeticException("除数为0");
            if (a > 0) {
                result = Double.POSITIVE_INFINITY;
            } else {
                result = Double.NEGATIVE_INFINITY;
            }
        }
        return result;
    }
}
